<%@tag import="java.sql.Connection"%>
<%@tag import="by.epam.communalservices.dao.jdbc.JdbcDaoJkhWorker"%>
<%@tag import="by.epam.communalservices.entity.JkhWorker"%>
<%@tag import="java.util.List"%>

<%@ attribute name="name" required="true"%>
<%@ attribute name="selected" required="true"%>
<%@ attribute name="attr"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<select name="${name}" ${attr}>
	<OPTION VALUE='0' ${selected==0? 'SELECTED' : ''}><c:out value="не определено"/></OPTION>
	<%
		Long selected = 0L;
	    try {
	        selected = Long.parseLong(getJspContext().getAttribute("selected").toString());
	    } catch (NumberFormatException e) {
	    }
	    	JdbcDaoJkhWorker workerDao = new JdbcDaoJkhWorker((Connection) request.getSession().getAttribute("currentConnection"));
	        List<JkhWorker> workerList = workerDao.findAll();

	        for (JkhWorker item : workerList) {
	            out.println("<OPTION VALUE='" + item.getId() + "' " + (item.getId() == selected ? "SELECTED" : "") + ">"
	                    + item.getId().toString()+ ". "+ item.getName() + " " + item.getPatronymic() + "</OPTION>");
	        }
	%>

</select>
